package com.jw.qme.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jw.qme.domain.enun.FriendStatus;
import com.jw.qme.domain.po.Friend;
import com.jw.qme.mapper.FriendMapper;
import com.jw.qme.service.FriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName: com.jw.qme.service.impl
 * Datetime: 2025/4/4 下午7:31
 * Description:
 *
 * @author 汪佳泉
 * @version 1.0
 * @since 1.0
 */
@Service
public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend>
        implements FriendService {

    @Autowired
    FriendMapper friendMapper;

    @Override
    public List<Friend> getFriendByUsername(String username, boolean isNew) {
        LambdaQueryWrapper<Friend> wrapper = new LambdaQueryWrapper<>();
        if (!isNew) {
            wrapper.and(wrapper1 -> wrapper1
                    .eq(Friend::getUserId, username)
                    .or()
                    .eq(Friend::getFriendId, username)
            ).eq(Friend::getStatus, FriendStatus.ACCEPTED.getValue());
        } else {
            wrapper.eq(Friend::getFriendId, username)
                    .eq(Friend::getStatus, FriendStatus.PENDING.getValue());
        }
        return friendMapper.selectList(wrapper);
    }


}
